package com.moco.launcher.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.moco.launcher.R;
import com.moco.launcher.adapter.GuideFragmentAdapter;
import com.moco.launcher.listener.ViewPageListenerInterface;
import com.oazon.common.util.Utils;
import com.moco.launcher.view.CirclePageIndicator;
import com.oazon.common.Logger;

public class GuideActivity extends BaseFragmentActivity implements ViewPageListenerInterface {
	private static final String TAG = "GuideActivity";
	
	private GuideFragmentAdapter mAdapter = null;
	private ViewPager mPager = null;
	private CirclePageIndicator mIndicator = null;
	private Button mButton = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);		
		setContentView(R.layout.guide_layout);

		mAdapter = new GuideFragmentAdapter(getSupportFragmentManager());

		mPager = (ViewPager) findViewById(R.id.pager);
		mPager.setAdapter(mAdapter);

		mIndicator = (CirclePageIndicator) findViewById(R.id.indicator);
		mIndicator.setViewPager(mPager);
		mIndicator.setPageListener(this);

		mButton = (Button) this.findViewById(R.id.start);
		mButton.setVisibility(View.GONE);
		mButton.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				if (!Utils.isNetworkAvailable(GuideActivity.this)) {
					Logger.d(TAG, "isNetworkAvailable " + false);
					startSettingsActivity();
				} else {
					Logger.d(TAG, "isNetworkAvailable " + true);
					startMainActivity();
				}
			}
		});
	}

	private void startSettingsActivity() {
		Intent intent = new Intent(this, NewWifiSettingsActivity.class);
		startActivity(intent);
	}

	private void startMainActivity() {
		Intent intent = new Intent(this, MainActivity.class);
		startActivity(intent);
	}

	@Override
	public void onPageSelected(int arg0) {
		Logger.d(TAG, "onPageSelected " + arg0);
		if (arg0 == 3)
			mButton.setVisibility(View.VISIBLE);
		else
			mButton.setVisibility(View.GONE);
	}
}
